﻿Imports PTIC_Util
Imports System.Windows.Forms
Imports PTIC_GestionBDD
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Windows.Data


Namespace ViewModels

    Public Class ViewModelCmdEncoursImport
        Inherits ViewModelCommand

#Region "Variables privées"
        Private _model As Model
        Private _cmdParcourir As ICommand
        Private _cmdVisualiser As ICommand
#End Region

#Region "Constructeur"
        Public Sub New(ByVal Model As Model, ByVal DisplayName As String, ByVal Command As ICommand)
            MyBase.New(DisplayName, Command)
            _model = Model
        End Sub
#End Region

        Public ReadOnly Property NomBase() As String
            Get
                Return _model.Univers.listeTraitements.getTraitTbleEncours.nomCompletFichier.nomComplet
            End Get
        End Property
        Public ReadOnly Property Tables() As ObservableCollection(Of String)
            Get
                Return New ObservableCollection(Of String)(_model.Univers.listeTraitements.getTraitTbleEncours.getListTablesDispoBDD)
            End Get
        End Property
        Public ReadOnly Property NbColonnes() As Integer
            Get
                Return _model.Univers.listeTraitements.getTraitTbleEncours.getStatsTable.nbColonnes
            End Get
        End Property
        Public ReadOnly Property NbLignes() As Integer
            Get
                Return _model.Univers.listeTraitements.getTraitTbleEncours.getStatsTable.nbLignes
            End Get
        End Property

#Region "Commandes"

        Public Property cmdParcourir() As ICommand
            Get
                If _cmdParcourir Is Nothing Then
                    createCmd()
                End If
                Return _cmdParcourir
            End Get
            Private Set(ByVal value As ICommand)
                _cmdParcourir = value
            End Set
        End Property
        Public Property cmdVisualiser() As ICommand
            Get
                If _cmdVisualiser Is Nothing Then
                    createCmd()
                End If
                Return _cmdVisualiser
            End Get
            Private Set(ByVal value As ICommand)
                _cmdVisualiser = value
            End Set
        End Property

        Private Sub cmdParcourirExecute()

            Dim openFileDialog1 As New System.Windows.Forms.OpenFileDialog
            openFileDialog1.InitialDirectory = csteEmplacementDefautTbleEncours
            openFileDialog1.Filter = "Fichiers access (*.mdb)|*.mdb|Table SAS (*.sas7bdat)|*.sas7bdat"

            If openFileDialog1.ShowDialog() = DialogResult.OK Then
                'Initilisation du traitement de la table d'encours et de la librairie d'encours SAS
                Dim nomBDDEncours As New Cla_NomFichier(openFileDialog1.FileName)
                _model.Univers.initLibrairieEncours(nomBDDEncours)
                _model.Univers.listeTraitements.getTraitTbleEncours.nomCompletFichier = nomBDDEncours
                OnPropertyChanged("NomBase")
                OnPropertyChanged("Tables")
                OnPropertyChanged("NbColonnes")
                OnPropertyChanged("NbLignes")
            End If

        End Sub
        Private Function cmdParcourirCanExecute() As Boolean
            Return True
        End Function

        Private Sub cmdVisualiserExecute()
            MsgBox("Vous avez cliqué sur le bouton visualiser")
        End Sub
        Private Function cmdVisualiserCanExecute() As Boolean
            Return True
        End Function

        Private Sub createCmd()
            cmdParcourir = New DelegateCommand(Of Object)(AddressOf cmdParcourirExecute, AddressOf cmdParcourirCanExecute)
            cmdVisualiser = New DelegateCommand(Of Object)(AddressOf cmdVisualiserExecute, AddressOf cmdVisualiserCanExecute)
        End Sub

#End Region

    End Class

End Namespace